// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/accesscontrol/api/AccessControlOrganPointApi'

import ComClass from '@api/ComQuery'
import InfoClass from '@api/accesscontrol/model/AccessControlOrganPointReq'
import SubmitClass from '@api/accesscontrol/model/AccessControlOrganPointAuthReq'
import BaseClass from '@api/accesscontrol/model/AccessControlOrganPointDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'dto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo(param, TIP = '查询信息') {
    const DTO = CORE.grpcDTO(InfoClass, param, COM, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'accessControlOrganPointQuery', DTO)
    return resp
  },
  transInfo(obj) {
    return { authList: obj.dto || [] }
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submit({ organId, bindIdList, unbindIdList }, TIP = '提交') {
    if (bindIdList.length) {
      const DTO = CORE.grpcDTO(SubmitClass, { organId, pointIds: bindIdList, authType: 1 })
      await CORE.grpc(TIP, CLIENT, 'accessControlOrganPointAuth', DTO)
    }
    if (unbindIdList.length) {
      const DTO = CORE.grpcDTO(SubmitClass, { organId, pointIds: unbindIdList, authType: 2 })
      await CORE.grpc(TIP, CLIENT, 'accessControlOrganPointAuth', DTO)
    }
    return CORE.grpcOK(TIP)
  },
}
